home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ddx-mips.zip / MIPS2030.C < prev    next >
C/C++ Source or Header  |  1992-07-31  |  4KB  |  149 lines

  1. /*
  2.  * $XConsortium$
  3.  *
  4.  * Copyright 1991 MIPS Computer Systems, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of MIPS not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  MIPS makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * MIPS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL MIPS
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #ident    "$Header: mips2030.c,v 1.7 91/11/12 12:11:30 dd Exp $"
  24.  
  25. #include <sys/types.h>
  26. #include <sysv/sys/grafreg.h>
  27. #include <sysv/sys/termio.h>
  28. #include <sysv/sys/kbd_ioctl.h>
  29.  
  30. #include <X.h>
  31. #include <Xproto.h>
  32. #include <misc.h>
  33. #include <colormapst.h>
  34. #include <input.h>
  35. #include <scrnintstr.h>
  36.  
  37. #include "mips.h"
  38. #include "mipsFb.h"
  39. #include "mipsKbd.h"
  40. #include "mipsIo.h"
  41. #include "mips2030.h"
  42.  
  43. #ifndef MIPSEL
  44.  
  45. extern char *mipsMapit();
  46.  
  47. static void Blank2030();
  48. static int WriteCMapIoctl();
  49. static void WriteCMap2030();
  50.  
  51. Bool
  52. mipsMap2030(pm)
  53.     MipsScreenPtr pm;
  54. {
  55.     if (!pm->fbreg && (
  56.         !(pm->fbnocache = (unsigned char *) mipsMapit((char *) 0,
  57.             GBUFKEY, GRAPHICS_FRAME_SIZE)) ||
  58.         !(pm->fbreg = (unsigned char *) mipsMapit((char *) 0,
  59.             GREGKEY, GRAPHICS_REG_SIZE))))
  60.         return FALSE;
  61.  
  62.     pm->fbnorm = pm->fbnocache;
  63.  
  64.     mipsInitColor(pm);
  65.  
  66.     pm->fb_width = RS2030_BPSL;
  67.     pm->Blank = Blank2030;
  68.  
  69.     /* open keyboard for colormap access */
  70.     openKeybd();
  71.  
  72.     /* KTCWRTCOLOR is broken in RISC/os 5.0 beta kernels */
  73.     if (WriteCMapIoctl(pm, 0, 0, (unsigned char *) pm))
  74.         pm->WriteCMap = (void (*)()) WriteCMapIoctl;
  75.     else {
  76.         pm->WriteCMap = WriteCMap2030;
  77.         keybdPriv.cap &= ~DEV_COLORMAP;
  78.     }
  79.  
  80. #if MIPS_4BIT
  81.     {
  82.         struct bt458 *ramdac =
  83.             &((struct rs2030_reg *) pm->fbreg)->ramdac;
  84.  
  85.         /*
  86.          * Set read mask for number of planes populated.
  87.          * XXX The PROM and/or kernel should take care of this.
  88.          */
  89.         ramdac->addr = BT458_READMASK;
  90.         ramdac->ctrl = (1 << pm->depth) - 1;
  91.     }
  92. #endif /* MIPS_4BIT */
  93.  
  94.     return TRUE;
  95. }
  96.  
  97. static void
  98. Blank2030(pm, on)
  99.     MipsScreenPtr pm;
  100.     Bool on;
  101. {
  102.     struct rs2030_reg *reg = (struct rs2030_reg *) pm->fbreg;
  103.  
  104.     if (on != SCREEN_SAVER_ON)
  105.         reg->unblank = 0;
  106.     else
  107.         reg->blank = 0;
  108. }
  109.  
  110. /*ARGSUSED*/
  111. static int
  112. WriteCMapIoctl(pm, index, count, rgb)
  113.     MipsScreenPtr pm;
  114.     int index;
  115.     int count;
  116.     unsigned char *rgb;
  117. {
  118.     struct colorm cm;
  119.  
  120.     cm.cmstart = index;
  121.     cm.cmcount = count;
  122.     bcopy((char *) rgb, (char *) cm.cmap, count * 3);
  123.  
  124.     return sysvIoctl(keybdPriv.fd, KTCWRTCOLOR, &cm) >= 0;
  125. }
  126.  
  127. static void
  128. WriteCMap2030(pm, index, count, rgb)
  129.     MipsScreenPtr pm;
  130.     int index;
  131.     int count;
  132.     unsigned char *rgb;
  133. {
  134.     struct bt458 *ramdac =
  135.         &((struct rs2030_reg *) pm->fbreg)->ramdac;
  136.     volatile unsigned char *out = &ramdac->cmap;
  137.  
  138.     ramdac->addr = index;
  139.  
  140.     while (--count >= 0) {
  141.         *out = rgb[0];
  142.         *out = rgb[1];
  143.         *out = rgb[2];
  144.         rgb +=3;
  145.     }
  146. }
  147.  
  148. #endif /* not MIPSEL */
  149.